package app.fichajes.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;



public class FormatCalendar {

	
	/**
	 * Formats for formated.
	 */
	public static final String month = "MMM";
	public static final String dayTH = "dd'th'";
	public static final String dayST = "dd'st'";
	public static final String dayND = "dd'nd'";
	public static final String dayRD = "dd'rd'";
	public static final String day = "dd";
	public static final String HOUR_SESSION = "HH:mm";
	public static final String DAY_SESSION = "yyyy'-'MM'-'dd";
	private static final int FIRST = 1, SECOND = 2, THIRD = 3;
	//private static String tag = "FormatCalendar";

	public static String getFormatedCalendar(Calendar calendar, String format) {
		Calendar calendarTmp = changeCalendar(calendar);
		
		//Log.d(tag , FinderObjectFromF1Data.getCountry(circuit.getCountry_id()).getGmt()+ " --> GMT ==> CalendarTMP = "+calendarTmp.get(Calendar.HOUR_OF_DAY));
		if (format.equals(dayTH)) {
			format = changeFormat(calendarTmp);
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);

		return sdf.format(calendarTmp.getTime());
	}

	public static Calendar changeCalendar(Calendar calendar) {
		
		Calendar calendarPhone = Calendar.getInstance();
		Long gmtCountry = (long)new Date().getTimezoneOffset();	
		return CalendarUtils.convertCalendarHourToPhone(calendar, calendarPhone, gmtCountry);
	}

	private static String changeFormat(Calendar calendar) {
		SimpleDateFormat sdf = new SimpleDateFormat(FormatCalendar.day);
		int day = Integer.parseInt(sdf.format(calendar.getTime()));

		switch (day) {
		case FIRST:
			return dayST;

		case SECOND:
			return dayND;
		case THIRD:
			return dayRD;
		default:
			break;
		}
		return dayTH;
	}
	
	
	/** Transforma la hora tipo calendar en tipo string **/
	public static String calendarToString(Calendar c){
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
		String hora = simpleDateFormat.format(c.getTime());
		
		return hora;
	}
	
	
}
